<template>
  <el-row>
    <el-col :span="20">
      <span :class="isRoot?'company-tit':'dept-tit'">
        <!-- <i class="el-icon-s-platform" /> -->
        {{ row.name }}
      </span>
    </el-col>
    <el-col :span="4" class="company-option">
      <span>{{ row.manager }}</span>
      <el-dropdown>
        <span class="el-dropdown-link">
          操作<i class="el-icon-arrow-down el-icon--right" />
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item @click.native="$emit('addDept', row)">添加子部门</el-dropdown-item>
          <el-dropdown-item v-if="!isRoot" @click.native="$emit('editDept', row)">查看部门</el-dropdown-item>
          <!-- 在组件上绑定点击事件 要加.native  加了之后将事件绑定在组件内的根元素上 -->
          <el-dropdown-item v-if="!isRoot" @click.native="delDept">删除部门</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </el-col>
  </el-row>
</template>

<script>
import { delDempByIdAPI } from '@/api/departments'
export default {
  props: {
    // 一行的数据
    row: {
      type: Object,
      required: true
    },
    // 是否是跟元素
    isRoot: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    // 删除部门
    delDept() {
      this.$confirm('此操作将永久删除该部门, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async() => {
        await delDempByIdAPI(this.row.id)
        this.$emit('ondel')
        this.$message({
          type: 'success',
          message: '删除成功!'
        })
      }).catch(() => {})
    }
  }
}
</script>

<style scoped lang="scss">
.el-row {
  width: 100%;
}
 .company-tit{
   font-size: 16px;
   font-weight: 700;
 }

.dept-tit {
  font-size: 14px;color: #000;
}
 .company-option {
   display: flex;
   justify-content: end;
   span:nth-child(1) {
     margin-right: 10px;
   }
 }

 .el-dropdown-menu {
  .el-dropdown-menu__item{
    color: skyblue;
   }
 }
</style>
